﻿B@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/Admin/_AdminLayout.cshtml";
}
@model IEnumerable<BabyToys.Models.DanhMuc>

<div id="content" class="span10">
    <!-- content starts -->
    <div>
        <ul class="breadcrumb">
            <li>
                <a href="#">Home</a> <span class="divider">/</span>
            </li>
            <li>
                <a href="#">Danh sách danh mục</a>
            </li>
        </ul>
    </div>
    <div class="row-fluid sortable">
        <div class="box span12">
            <div class="box-content">
                <div class="row-fluid">
                    <div class="span12 form-inline">
                        @using (Html.BeginForm("Index", "AdminDanhMuc", FormMethod.Get))
                        {
                            <div id="search-box" style="text-align: left">
                                Tên danh mục
                                <input type="text" name="SearchString" class="input" value="@ViewBag.CurrentFilter" placeholder="Tên danh mục..."/>
                                <button class="btn btn-small" type="submit"><i class="icon-search"></i>Tìm kiếm</button>
                            </div>
                        }
                    </div>

                </div>
                <div class="row-fluid">
                    <div class="span4">
                        <a href="~/AdminDanhMuc/themmoi" class="btn btn-large btn-success">
                            <i class="icon-plus icon-white"></i>
                            Thêm mới
                        </a>
                    </div>
                </div>

            </div>
            <div class="clearfix"></div>
            <table class="table table-striped table-bordered bootstrap-datatable datatable">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Tên danh mục</th>
                        <th>Danh mụcc cha</th>
                        <th>Active</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @RenderTable(Model, 1, "")
                </tbody>
            </table>

        </div>
    </div>
</div>

@helper RenderTable(IEnumerable<BabyToys.Models.DanhMuc> DanhMucList, int id, string prefix)
{
    foreach (var dm in DanhMucList.Where(d => d.DanhMucCha.IdDanhMuc == id))
    {
        string prefix1 = prefix;
    <tr class="item_row" style="border-color: #F0F0F0; border-style: Solid; height: 40px;">

        <td class="item_float">
            <input type="hidden" value="@dm.IdDanhMuc" id="txtId"/>
            @dm.IdDanhMuc
        </td>
        <td class="item_float" style="text-align: left;">
            <input type="hidden" value="@dm.TenDanhMuc" id="txtTen"/>
            @prefix1@dm.TenDanhMuc
        </td>
        <td class="item_float">
            <input type="hidden" value="@dm.DanhMucCha.IdDanhMuc" id="txtDanhMucCha"/>
            @dm.DanhMucCha.TenDanhMuc
        </td>
        <td class="item_float">
            @{int idd = dm.IdDanhMuc;}
            <input id="@Html.Raw("HienThi" + dm.IdDanhMuc)" type="checkbox" onclick="CapNhatHienThi(@idd)" 
                @if (dm.IsActive == true){@:checked="checked"
                            }
                @Html.Raw(ViewBag.Xoa == true ? "" : "disabled=\"disabled\"")
                            />
            <script type="text/ecmascript">
                function CapNhatHienThi(id) {
                    var ten = '#HienThi' + id;
                    var hienthi = $(ten).is(':checked') ? true : false;
                    //alert("a:"+x+"b:"+id);
                    var x = confirm("Bạn có chắcc mún thay đổi danh mục này?")
                    if(x==true)
                    {
                        $.post("/AdminDanhMuc/CapNhatHienThi/", { "id": id, "hienthi": hienthi },
                               function (data) {
                                   alert("Cập Nhậtt Thành Công");
                                   window.location.reload();
                               });
                    }
                    else
                    {
                        window.location.reload();
                    }
                }
            </script>
        </td>
        <td class="td-actions">
            <div class="hidden-phone visible-desktop action-buttons">
                <a href="~/AdminDanhMuc/sua/@dm.IdDanhMuc" class="btn btn-info">
                    <i class="icon-edit icon-white"></i>
                    Sửa
                </a>
            </div>
        </td>
    </tr>
                                                                                                           prefix1 += "________";
    @RenderTable(DanhMucList, dm.IdDanhMuc, prefix1)
    }
}